package cn.htsyb.synergy.security.bean.param;

import cn.htsyb.synergy.orm.jpa.criterion.ExpressBuilder;
import cn.htsyb.synergy.orm.jpa.criterion.QueryExpress;
import cn.htsyb.synergy.orm.jpa.model.param.AbsStandardParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.StringUtils;

import java.util.List;
/**
 * 角色 参数类
 * codeMaker at 2020-07-14
 * @author lakeside hubin_yuan.410@hotmail.com
 * @since 2020-07-14
 */
@Setter
@Getter
@Schema(description = "角色参数")
public class SecurityRoleParam extends AbsStandardParam {
    /**角色编码*/
    @Schema(name = "roleCode", description = "角色编码 ")
    protected  String roleCode;
    /**角色名称*/
    @Schema(name = "roleName", description = "角色名称 ")
    protected  String roleName;

    /**通用过滤*/
    @Schema(name = "filter", description = "通用过滤")
    protected String filter;

    @Override
    public List<QueryExpress> searchCriterion() {
        return ExpressBuilder.instance(super.searchCriterion())
                    .addExpressOfOperator(!StringUtils.isEmpty(roleCode), "roleCode", QueryExpress.Operator.EQ, roleCode)
                    .addExpressOfOperator(!StringUtils.isEmpty(roleName), "roleName", QueryExpress.Operator.EQ, roleName)
                .build();
    }

    @Override
    public List<QueryExpress> filterCriterion() {
        boolean bool=!StringUtils.isEmpty(filter);

        return ExpressBuilder.instance(super.filterCriterion())
                /*需要自行根据索引调整可支持的通用查询字段，切不可全字段通用查询
                .addExpressOfOperator(bool,"roleCode",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"roleName",QueryExpress.Operator.LIKE, filter)
                 */
                .build();
    }
}